<template>
  <div class="page-container">
    <div class="common-content-wrap">
      <TrTable
        v-model="searchParams"
        :searchShowList="searchShowList"
        :searchHideList="searchHideList"
        :minSearchLabelWidth="100"
        :tableData="tableData"
        :tableColumn="tableColumn"
        :total="totalNum"
        requestName="searchHandle"
        @rowDown="operateHandle($event)"
      />
    </div>
  </div>
</template>

<script>
import { getList, getBizMould } from "@/api/system/export";
// import { exportFileById } from "@/api/base/base";
import { getColor } from "@/utils/billColor";
import { comExportFileByUrl } from "@/utils/util";
import TrTable from "@/components/Tr-table/Tr-table.vue";
export default {
  name: "exportBox",
  components: {
    TrTable,
  },
  data: () => ({
    totalNum: 0,
    tableData: [],
    searchParams: {
      current: 1,
      size: 10,
    },
    searchShowList: [
      {
        label: "业务类型",
        type: "multiSelect",
        width: 33.3,
        value: [],
        id: "taskIdList",
        list: [],
      },
    ],
    searchHideList: [
      {
        startStr: "createTimeStart",
        endStr: "createTimeEnd",
        id: "createdTime",
        type: "daterange",
        width: 80,
        label: "开始结束时间",
        value: [],
        timePeriod: true,
        radio: 1,
      },
    ],
    tableColumn: [
      {
        type: "text",
        label: "文件名称",
        value: "fileName",
      },
      {
        type: "text",
        label: "业务类型",
        value: "bizMouldName",
      },
      {
        type: "text",
        label: "下载状态",
        value: "exportStatusName",
      },
      {
        type: "text",
        label: "开始时间",
        value: "createTime",
      },
      {
        type: "text",
        label: "结束时间",
        value: "updateTime",
      },
      {
        type: "text",
        label: "失败原因",
        value: "errorMsg",
      },
      {
        type: "option",
        label: "操作",
        fixed: "right",
        width: 80,
        showBtnList: [
          {
            label: "下载",
            option: "rowDown",
          },
        ],
      },
    ],
  }),
  methods: {
    async operateHandle(val) {
      // let res = await exportFileById(val.id);
      // if (res.status !== 200) return this.$message.error(res.statusText);
      // this.$message.success(this.$t("downLoad.success"));
      // let fileName = `${val.bizMouldName}-${val.fileName}`;
      // comExport(res.data, fileName);
      if (val.fileUrl == "-") return this.$message.warning("暂无下载地址");
      comExportFileByUrl(val.fileUrl, val.fileName);
    },
    getListHandle(params) {
      getList(params).then((res) => {
        if (res.data.code != 200) return this.$message.error(res.data.msg);
        let data = res.data.data;
        this.$validateData(data);
        this.totalNum = data.total;
        this.tableData = data.records;
        this.tableData.forEach((item) => {
          item["exportStatusNameColor"] = getColor("XZZT", item.exportStatus);
          item["isShowdown"] = item.exportStatus != 30;
        });
      });
    },
    searchHandle() {
      this.getListHandle(this.searchParams);
    },
    async getBizMouldHandle() {
      const res = await getBizMould();
      let list = res.data.data.records.map((item) => {
        return {
          label: item.bizMouldName,
          value: item.id,
        };
      });
      const hCol = this.$findByProperty(
        this.searchShowList,
        "id",
        "taskIdList"
      );
      this.$set(hCol, "list", list);
    },
  },
  mounted() {
    // this.searchHandle();
    this.getBizMouldHandle();
  },
};
</script>

<style></style>
